package com.sy.test.takenumberdemo.model;

import android.util.Log;


import com.sy.test.takenumberdemo.bean.BaseBean;
import com.sy.test.takenumberdemo.bean.Game;
import com.sy.test.takenumberdemo.bean.GameTime;
import com.sy.test.takenumberdemo.contract.EndContract;
import com.sy.test.takenumberdemo.net.api.FollowService;
import com.sy.test.takenumberdemo.net.retrofit.BaseObserver;
import com.sy.test.takenumberdemo.net.retrofit.RetrofitServiceManager;
import com.sy.test.takenumberdemo.net.retrofit.RxUtils;
import com.sy.test.takenumberdemo.presenter.EndPresenter;

import java.util.ArrayList;
import java.util.HashMap;

public class EndModel extends BaseModelImpl implements EndContract.Model {
    private EndPresenter endPresenter;
    public EndModel(EndPresenter presenter){
        endPresenter = presenter;
    }
    ArrayList<Game> newList;
    HashMap<String,GameTime> gameTimeList;
    @Override
    public void getGameData(String page, String week) {
        addSubscribe(RetrofitServiceManager.getInstance().creat(FollowService.class)
                .getGameData(page, 10,week)
                .compose(RxUtils.rxSchedulerHelper())
                .compose(RxUtils.handleResult())
                .subscribeWith(new BaseObserver<BaseBean<ArrayList<Game>>>() {

                    @Override
                    public void onError(Throwable e) {
                        super.onError(e);
                    }

                    @Override
                    protected void onSuccess(BaseBean<ArrayList<Game>> arrayListBaseBean) {
                        Log.e("weichongbin","数据接收成功");
                        if (newList!=null){
                            newList.clear();
                        }
                        if (arrayListBaseBean.getNewCode()!=3001){
                            newList = arrayListBaseBean.getNewData();
                        }
                        gameTimeList = arrayListBaseBean.getDate_res();
                        endPresenter.onGetGameData(newList,gameTimeList);
                    }
                }));
    }
}
